import time

count = 10
square_generator = (x**2 for x in range(count))

for i in range(count):
    time.sleep(0.5)
    print("生成器生成的值为：", next(square_generator))

try:
    print("开始用for循环来迭代生成器")
    for item in square_generator:
        print("生成器生成的值为：", item)
except StopIteration as e:
    print("square_generator已经被消耗完了，请重新生成square_generator生成器", e)
